﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using ExtAspNet;
using FJASPX.Framwork.UI;
using FJASPX.Service;
using FJASPX.Framwork.Helper;
using FJASPX.Framwork.Constant;

namespace PlugNT.Cms.Web.Member
{
    public partial class ChangePassword : EditPageBase<FJASPX.Domain.User>
    {
        public IUserService iUserService { get; set; }

        #region Property属性
        public override string PowerCode
        {
            get { throw new NotImplementedException(); }
        }
        #endregion

        #region Methods方法
        protected override bool FirstCallRead()
        {
            //初始化控件
            this.btn_BReturn = this.btn_Return;
            this.IsUpdate = true;
            base.FirstCallRead();
            return true;
        }
        #endregion

        #region Events事件
        protected void btn_Submit_Click(object sender, EventArgs e)
        {
            this.Model = iUserService.GetUserByName(this.CurrentUser.UserName);
            try
            {
                if (!this.Model.IsNull())
                {
                    string pwd = this.txt_Oldpwd.GetValue();
                    if (this.Model.PassWord.Equals(pwd))
                    {
                        this.Model.PassWord = this.txt_Confirmpwd.GetValue();
                        iUserService.Save(this.Model);
                        this.Success(); //这里加清缓存操作
                        PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
                    }
                    else {
                        Alert.ShowInTop(Strings.PASSWORD_ERROR, Strings.ALERT);
                    }
                    return;
                }

            }
            catch (Exception ex)
            {
                Log.WriteLog(Message.ERR, ex);
            }
            this.Fail();
        }
        #endregion
    }
}